<template>
  <div>
    <!--搜索查询-->
    <el-row>
      <el-col :span="3">
        <el-input v-model="searchForm.username" size="mini" placeholder="请输名称"></el-input>
      </el-col>
      <el-col :span="3">
        <el-input v-model="searchForm.carName" size="mini" placeholder="请输车辆名"></el-input>
      </el-col>
      <el-col :span="3">

      </el-col>
      <el-col :span="2">
        <el-button type="primary" size="mini" @click="search()" icon="el-icon-search">搜索
        </el-button>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" size="mini" @click="flush()" icon="el-icon-refresh">刷新</el-button>
      </el-col>
      <el-col :span="3">

      </el-col>
    </el-row>

    <el-row>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="120" align="center" v-if="false"></el-table-column>
        <el-table-column prop="username" label="用户名" width="120" align="center"></el-table-column>
        <el-table-column prop="carName" label="车辆名" width="120" align="center"></el-table-column>
        <el-table-column prop="startTime" label="开始时间" width="180" align="center"> </el-table-column>
        <el-table-column prop="endTime" label="结束时间" width="180" align="center"> </el-table-column>
        <el-table-column prop="sname" label="租出门店" width="150" align="center"> </el-table-column>
        <el-table-column prop="sname" label="归还门店" width="150" align="center"> </el-table-column>
        <el-table-column prop="totalPrice" label="总金额" width="130" align="center"> </el-table-column>
        <el-table-column prop="preparidAmount" label="预付金额" width="130" align="center"> </el-table-column>
        <el-table-column prop="isgetcarathome" label="是否送车上门" width="120" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.isgetcarathome == 0">否</p>
            <p v-else-if="scope.row.isgetcarathome == 1">是</p>
          </template>
        </el-table-column>
        <el-table-column prop="detailAddr" label="送车上门地址" width="130" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="isreturncarathome" label="是否上门还车" width="120" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.isreturncarathome == 0">否</p>
            <p v-else-if="scope.row.isreturncarathome == 1">是</p>
          </template>
        </el-table-column>
        <el-table-column prop="returnCarAddr" label="还车上门地址" width="130" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="addtime" label="添加时间" width="180" align="center"> </el-table-column>
        <el-table-column prop="carDeposit" label="车辆押金" width="100" align="center"> </el-table-column>
        <el-table-column prop="violationDeposit" label="违章押金" width="100" align="center"> </el-table-column>
        <el-table-column prop="maintainShopId" label="维修厂ID" width="100" align="center" v-if="false"> </el-table-column>

        <el-table-column prop="rcId" label="操作编号" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="orderId" label="订单编号" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="state" label="还车状态" width="100" align="center" :formatter="rcFormat" >
          <template slot-scope="scope">
            <p v-if="scope.row.state == 1">正常</p>
            <p v-else-if="scope.row.state == 2">正常</p>
            <p v-else-if="scope.row.state == 3">正常</p>
            <p v-else-if="scope.row.state == 4">正常</p>
          <p v-else-if="scope.row.state == 5">正常</p>
            <p v-else-if="scope.row.state == 6">正常</p>
          </template>

        </el-table-column>
        <el-table-column prop="description" label="描述" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="carId" label="汽车编号" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="payMoney" label="付款金额" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="addname" label="添加人" width="100" align="center" v-if="false"> </el-table-column>
        <el-table-column prop="rcAddtime" label="还车操作时间" width="100" align="center" v-if="false">> </el-table-column>
        <el-table-column prop="mrAddtime" label="维修操作时间" width="100" align="center" v-if="false">> </el-table-column>
        <el-table-column prop="state" label="订单状态" :formatter="orderFormat" width="100" align="center"></el-table-column>
        <el-table-column prop="cstate" label="汽车状态" width="100" align="center" :formatter="crFormat"> </el-table-column>



        <el-table-column label="还车详情" width="150" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"  v-if="scope.row.state == 4" >查看详情</el-button>
          </template>
        </el-table-column>

<!--        <el-table-column label="维修信息添加" width="150" fixed="right" align="center" >-->
<!--          <template slot-scope="scope" >-->
<!--            <el-button size="mini" @click="WxhandleEdit(scope.$index, scope.row)"  v-if="scope.row.cstate == 2 ">维修信息添加</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->

      </el-table>
    </el-row>
    <el-row>
      <!--分页插件-->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[2, 3, 8, 5, 10, 20, 100]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </el-row>

    <!-- 还车操作信息 -->
    <el-dialog :title="title" :visible.sync="dialogFormVisibleAdd">
      <el-form :model="form" :rules="rules" ref="form" enctype="multipart/form-data">

        <el-form-item label="还车订单状态" prop="state" :label-width="formLabelWidth">
          <el-select disabled v-model="form.state" placeholder="请选择还车订单状态">
            <el-option label="使用中" value="4"></el-option>
            <el-option label="已交还" value="5"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="汽车状态操作" prop="cstate" :label-width="formLabelWidth">
          <el-select disabled v-model="form.cstate" placeholder="请选择汽车状态">
            <el-option label="可租" value="1"></el-option>
            <el-option label="维修中" value="2"></el-option>
            <el-option label="已租出" value="3"></el-option>
            <el-option label="删除" value="4"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="还车订单类型" prop="idType" :label-width="formLabelWidth">
          <el-select disabled v-model="form.idType" placeholder="请选择还车订单类型">
            <el-option label="正常" value="1"></el-option>
            <el-option label="逾期" value="2"></el-option>
            <el-option label="事故" value="3"></el-option>
            <el-option label="其他" value="4"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="汽车品牌" prop="description" :label-width="formLabelWidth">
          <el-input v-model="form.carName" disabled autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="付款金额" prop="totalPrice" :label-width="formLabelWidth">
          <el-input v-model="form.totalPrice" disabled autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="添加时间" prop="startTime" :label-width="formLabelWidth">
          <el-date-picker v-model="form.startTime" disabled type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择添加时间">
          </el-date-picker>
        </el-form-item>

      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibleAdd = false">取 消</el-button>
        <el-button type="primary" @click="Submit('form')">确 定</el-button>
      </div>

    </el-dialog>



    <!-- 维修厂信息表单 -->
    <el-dialog :title="title" :visible.sync="WxdialogFormVisibleAdd">
      <!-- <el-radio-group v-model="labelPosition" size="small">
        <el-radio-button label="left">左对齐</el-radio-button>
        <el-radio-button label="right">右对齐</el-radio-button>
        <el-radio-button label="top">顶部对齐</el-radio-button>
      </el-radio-group> -->
      <el-form :model="form" :rules="rules" ref="form" enctype="multipart/form-data" >

        <!-- <el-form-item label="汽车品牌" prop="brand.name" :label-width="formLabelWidth">
          <el-select v-model="form.brandId" @change="changeA" placeholder="请选择">
            <el-option v-for="item in optionsA" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item> -->

        <!-- <el-form-item label="汽车名称" prop="carname" :label-width="formLabelWidth">
                <el-select v-model="form.carName"  placeholder="请选择">
                    <el-option
                            v-for="item in optionsB"
                            :key="item.id"
                            :label="item.carname"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item> -->

        <el-form-item label="汽车品牌" prop="carname" :label-width="formLabelWidth" :disabled="true">
          <el-input v-model="form.carName" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="修车公司" prop="maintainShop.name" :label-width="formLabelWidth" >
          <el-select v-model="form.maintainShopId" placeholder="请选择">
            <el-option v-for="item in optionsC" :key="item.id" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="金额" prop="amount" :label-width="formLabelWidth">
          <el-input v-model="form.amount" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="添加时间" prop="mrAddtime" :label-width="formLabelWidth">
          <el-date-picker v-model="form.mrAddtime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择添加时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="WxdialogFormVisiblExit('form')">取 消</el-button>
        <el-button type="primary" @click="WxSubmit('form')">确 定</el-button>
      </div>
    </el-dialog>





  </div>
</template>

  <script>
export default {
  data() {
    return {
      formLabelWidth: "120px",
      labelPositon: 'left',
      title: "",
      rules: {},
      tableData: [],
      dialogFormVisibleAdd: false,
      WxdialogFormVisibleAdd: false,
      currentPage: 1, //页码 第几页
      pageSize: 8, //每页显示数量
      total: 100, //总条数              
      form: {},//form表单对象
      form1: {},//form表单对象
      searchForm: {
        carName: '', username: ''
      },//搜索form表单

      data: [],
      optionsA: [],
      optionsB: [],
      optionsC: [],
    };
  },
  created() {
    this.loadData();

    var _this = this;
    // _this.$http
    //   .post("/brand/queryByPage", {
    //     pageNo: this.currentPage,
    //     pageSize: 100,
    //     data: {},
    //   })
    //   .then(function (response) {
    //     console.log(JSON.stringify(response));
    //     if (response.data.code == 200) {
    //       _this.optionsA = response.data.data.list;
    //       _this.total = response.data.data.total;
    //     }
    //   })
    //   .catch(function (error) {
    //     //错误的处理
    //     // handle error
    //     console.log(error);
    //   })
    //   .then(function () {
    //     //总执行 最终处理      类似java  异常处理的finally
    //     // always executed
    //   });

    _this.$http
      .post("/maintainShop/queryByPage", {
        pageNo: this.currentPage,
        pageSize: 100,
        data: {},
      })
      .then(function (response) {
        console.log(JSON.stringify(response));
        if (response.data.code == 200) {
          _this.optionsC = response.data.data.list;
          //_this.total = response.data.data.total;
        }
      })
      .catch(function (error) {
        //错误的处理
        // handle error
        console.log(error);
      })
      .then(function () {
        //总执行 最终处理      类似java  异常处理的finally
        // always executed
      });



  },
  //所有函数
  methods: {
    //加载数据
    loadData(){
      this.$http.post("/order/member/select?currentPage="+this.currentPage+"&pageSize="+this.pageSize,this.searchForm).then(resp=>{
        console.log(resp)
        if(resp.data.code==2000){
          this.tableData=resp.data.data.list;
          this.total=resp.data.data.total;
        }else if (resp.data.code==4001){
          this.$message.error("未登录");
          this.$router.push("/login");
        }

      })
    },
    rcFormat(row, column, cellValue, index) {
      var returnValue = "";
      if (cellValue == 1) {
        returnValue = "正常";
      } else if (cellValue == 2) {
        returnValue = "逾期";
      } else if (cellValue == 3) {
        returnValue = "事故";
      } else if (cellValue == 4) {
        returnValue = "其他";
      }
      return returnValue;
    },

    crFormat(row, column, cellValue, index) {
      var returnValue = "";
      if (cellValue == 1) {
        returnValue = "可租";
      } else if (cellValue == 2) {
        returnValue = "维修中";
      } else if (cellValue == 3) {
        returnValue = "已出租";
      } else if (cellValue == 4) {
        returnValue = "删除";
      }
      return returnValue;
    },

    //处理每页数量发生变化
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      //让每页数量发生变化
      this.pageSize = val;
      //重载数据
      this.loadData();
    },
    //处理当前页变化
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      //让每页数量发生变化
      this.currentPage = val;
      //重载数据
      this.loadData();
    },

    //查询
    search() {
      this.loadData();
    },
    //还车订单操作
    handleEdit(index, row) {
      var _this = this;
      //row  当前行数据 如果是第一行  row = {deptId:1,deptName:'管理部',description:'店长的事',status:1}
      console.log("------------====" + index, row);
      //显示对话框
      _this.dialogFormVisibleAdd = true;
      //指定对话框标题
      _this.title = '';
      //把一行数据赋值给form赋值
      _this.form = row;

      _this.form.type = row.type + "";
      _this.form.cstate = row.cstate + "";
      _this.form.state = row.state + "";

      // if (_this.form.rcId == null) {
      //   _this.title = '操作添加';
      //   _this.form.orderId = _this.form.id
      // } else {
      //   _this.title = '操作更新';
      // }

    },
    Submit(form) {

      this.$refs[form].validate((valid) => {
        this.dialogFormVisibleAdd = false;
        // if (valid) {
        //   var url = "";
        //   // if (this.title == "操作添加") {
        //   //   url = "/returnCheck/add";
        //   // } else {
        //   //   url = "/order/edit";
        //   // }
        //     // url = "/returnCheck/add";
        //      url = "/order/edit";
        //
        //   //让_this等于当前vue对象
        //   var _this = this;
        //   // alert(111);
        //   console.log(JSON.stringify("---------------->>>" + this.form))
        //   //赋值 axios官网代码  this.form =form:{deptName:'',description:'',status:1}
        //   _this.$http.post(url, this.form)  //指定请求的url及参数  get
        //     .then(function (response) {  //正确返回对象的处理
        //       // handle success
        //       console.log(response);
        //       //JSON.stringify   把json转换为json字符串，方便查看
        //       console.log("=====" + JSON.stringify(response));
        //       //直接使用this 会指 axios对象  错误
        //       // this.tableData
        //       //判断返回值是否正确
        //       if (response.data.code == 200) {
        //         //关闭弹框
        //         _this.dialogFormVisibleAdd = false;
        //         //提示添加成功
        //         _this.$message({
        //           message: '恭喜你，这是一条成功消息',
        //           type: 'success'
        //         });
        //         //重新加载数据
        //         _this.loadData();
        //       } else {
        //         //错误提示信息
        //         _this.$message.error('错了哦，这是一条错误消息');
        //       }
        //
        //     })
        //     .catch(function (error) {//错误的处理
        //       // handle error
        //       console.log(error);
        //     })
        // } else {
        //   console.log('error submit!!');
        //   return false;
        // }
      });
    },
    //取消按钮
    dialogFormVisiblExit(form) {
      this.dialogFormVisibleAdd = false;
    },

    //删除订单
    handleDelete(index, row) {
      console.log(index, row);
      //确认框提示
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        //让_this等于当前vue对象
        var _this = this;
        // alert(111);
        //赋值 axios官网代码  this.form =form:{deptName:'',description:'',status:1}
        _this.$http.delete("/order/deleteById?id=" + row.id)  //指定请求的url及参数  get
          .then(function (response) {  //正确返回对象的处理
            // handle success
            console.log(response);
            //JSON.stringify   把json转换为json字符串，方便查看
            console.log(JSON.stringify(response));
            //直接使用this 会指 axios对象  错误
            // this.tableData
            //判断返回值是否正确
            if (response.data.code == 200) {
              //提示添加成功
              _this.$message({
                message: '恭喜你，这是一条成功消息',
                type: 'success'
              });
              //重新加载数据
              _this.flush()
            } else {
              //错误提示信息
              _this.$message.error('错了哦，这是一条错误消息');
            }

          })
          .catch(function (error) {//错误的处理
            // handle error
            console.log(error);
          })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },



    //维修厂操作
    WxhandleEdit(index, row) {
      var _this = this;
      //row  当前行数据 如果是第一行  row = {deptId:1,deptName:'管理部',description:'店长的事',status:1}
      console.log("------------====" + index, row);
      //显示对话框
      _this.WxdialogFormVisibleAdd = true;
      //指定对话框标题
      _this.title = '';
      //把一行数据赋值给form赋值
      _this.form = row;

     


    },
    WxSubmit(form) {

      this.$refs[form].validate((valid) => {
        if (valid) {
          var url = "";
            url = "/order/addMaintainRecord"
          //让_this等于当前vue对象
          var _this = this;
          // alert(111);
          console.log(JSON.stringify("---------------->>>" + this.form))
          //赋值 axios官网代码  this.form =form:{deptName:'',description:'',status:1}
          _this.$http.post(url, this.form)  //指定请求的url及参数  get
            .then(function (response) {  //正确返回对象的处理
              // handle success
              console.log(response);
              //JSON.stringify   把json转换为json字符串，方便查看
              console.log("=====" + JSON.stringify(response));
              //直接使用this 会指 axios对象  错误
              // this.tableData
              //判断返回值是否正确
              if (response.data.code == 200) {
                //关闭弹框
                _this.WxdialogFormVisibleAdd = false;
                //提示添加成功
                _this.$message({
                  message: '恭喜你，这是一条成功消息',
                  type: 'success'
                });
                //重新加载数据
                _this.loadData();
              } else {
                //错误提示信息
                _this.$message.error('错了哦，这是一条错误消息');
              }

            })
            .catch(function (error) {//错误的处理
              // handle error
              console.log(error);
            })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    //取消按钮
    WxdialogFormVisiblExit(form) {
      this.WxdialogFormVisibleAdd = false;
    },



    //刷新
    flush() {
      location.reload();
    },
    orderFormat(row, column, cellValue, index) {
      //row当前行数据
      //column 列名称
      //cellValue 列的值
      //index 下标
      //alert(cellValue);
      return cellValue == 1 ? "输入" : cellValue == 2 ? "提交" : cellValue == 3 ? "预约" : cellValue == 4 ? "使用中" : cellValue == 5 ? "交还" : "取消";
    }

  },
};
</script>
  <style>
  </style>